package sunger.net.org.dropmenu.adapter;

import ohos.agp.components.*;
import ohos.agp.utils.Color;
import ohos.agp.utils.TextAlignment;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;

import java.util.Arrays;
import java.util.List;

/**
 * Created by sunger on 16/4/16.
 */
public class ShopAdapter extends BaseItemProvider {
    private final String[] data = {"shop1", "shop2", "shop3", "shop4", "shop5",
        "shop6", "shop7", "shop8", "shop9", "shop10",
        "shop11", "shop12", "shop13", "shop14", "shop15",
        "shop16", "shop17", "shop18", "shop19", "shop20",
        "shop21", "shop22", "shop23", "shop24", "shop25",
        "shop26", "shop27", "shop28", "shop29", "shop30"};
    private final Context context;
    private List<String> list;

    /**
     * 构造器
     *
     * @param context 上下文
     */
    public ShopAdapter(Context context) {
        this.context = context;
        list = Arrays.asList(data);
    }

    /**
     * 数量
     *
     * @return 数量
     */
    @Override
    public int getCount() {
        return list.size();
    }

    /**
     * 获取item
     *
     * @param position 位置
     * @return item
     */
    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    /**
     * 获取id
     *
     * @param position 位置
     * @return id
     */
    @Override
    public long getItemId(int position) {
        return position;
    }

    /**
     * 获取Component
     *
     * @param position 位置
     * @param component Component
     * @param componentContainer componentContainer
     * @return Component
     */
    @Override
    public Component getComponent(int position, Component component, ComponentContainer componentContainer) {
        Text text = new Text(context);
        text.setText(list.get(position));
        text.setHeight(300);
        text.setWidth(DisplayManager.getInstance().getDefaultDisplay(context).get().getRealAttributes().width);
        text.setTextSize(40);
        text.setTextColor(Color.DKGRAY);
        text.setTextAlignment(TextAlignment.TOP);
        return text;
    }
}
